//
//  LTConversation.h
//  LTIM
//
//  Created by 俊松何 on 2017/3/27.
//  Copyright © 2017年 俊松何. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "LTMessage.h"


@class LTMessage, LTTranslateModel,LTError,LTUser;
typedef enum {
  LTConversationTypeChat     = 1000,
  LTConversationTypeGroup    = 1001,
  LTConversationTypeChatRoom = 1002,
  LTConversationTypeGZH      = 1003
    
}LTConversationType;

/*
 *  \~chinese
 *  消息搜索方向
 *
 *  \~english
 *  Message search direction
 */
typedef enum{
    LTMessageSearchDirectionUp  = 0,    /*! \~chinese 向上搜索 \~english Search older messages */
    LTMessageSearchDirectionDown        /*! \~chinese 向下搜索 \~english Search newer messages */
} LTMessageSearchDirection;


@interface LTConversation : NSObject

@property(nonatomic,copy)   NSString   *conversationId;

@property(nonatomic,strong) LTUser     *conversationUser;

@property(nonatomic,assign) LTChatType chatType;

@property(nonatomic,strong) NSString *createTime;
/*
 *扩展属性
 *
 */
@property(nonatomic,copy)   NSString *extra;
/*
 *消息总数量
 *
 */
@property(nonatomic,assign) NSInteger msgCount;

/*
 *未读消息数量
 *
 */
@property(nonatomic,assign) NSInteger unReadCount;

/*
 *会话置顶 默认为NO
 *
 */
@property(nonatomic,assign) BOOL   isTop;
/*
 *消息免打扰 默认为NO
 *
 */
@property(nonatomic,assign) BOOL   isSilent;
/*
 *z最后一条消息的时间
 *
 */
@property(nonatomic,copy)   NSString *lastMsgTime;

@property(nonatomic,copy)   NSString *digest;

@property(nonatomic,copy)   NSString *digestUser;

@property(nonatomic,copy)   NSString *editingMsg;

@property(nonatomic,strong) LTMessage *lastMessage;



/*
 *当前回话需要翻译的对象model 如果model值为nil不需要翻译
 *
 */
@property(nonatomic,strong) LTTranslateModel *extModel;


-(void)insertMessage:(LTMessage *)aMessage
               error:(NSError **)error;

-(NSArray<LTMessage *> *)loadAllMessage;

- (void)loadMessagesStarttime:(double)time
                          count:(int)aCount
                searchDirection:(LTMessageSearchDirection)aDirection
                     completion:(void (^)(NSArray<LTMessage *> *aMessages, LTError *aError))aCompletionBlock;


- (void)loadMessagesStartMessageId:(NSString *)messageId
                            count:(int)aCount
                  searchDirection:(LTMessageSearchDirection)aDirection
                       completion:(void (^)(NSArray<LTMessage *> *aMessages, LTError *aError))aCompletionBlock;


-(void)markAllMessagesAsRead;

/*!
 *  \~chinese
 *  将消息设置为已读
 *
 *  @param aMessageId   要设置消息的ID
 *  @param pError       错误信息
 *
 */
- (BOOL)markMessageAsReadWithId:(NSString *)aMessageId
                          error:(LTError **)pError;


/**
 会话置顶

 @param istop 是否置顶
 @return 返回结果与否
 */
- (BOOL)markConversationisTop:(BOOL)istop;


/**
 消息免打扰

 @param isSilent 是否免打扰
 @return 设置成功与否
 */
- (BOOL)markConversationisSilent:(BOOL)isSilent;


/**
 删除该会话下的所有消息

 @return 删除成功与否
 */
- (BOOL)deleteAllMessage;

/**
  删除该会话下指定会话的消息

 @param messageId 消息id
 @return 删除成功与否
 */
- (BOOL)deleteAllMessageWithMessageId:(NSString *)messageId;



/**
 会话有人At我

 @return YES 有人At  NO没人At或者At已经看过了
 */
-(BOOL)haveAtMe;


-(BOOL)updateConversationToDB;

@end
